#!/usr/bin/python
#coding:utf-8
import httplib
#httplib.HTTPConnection.debuglevel = 1 
import urllib
#精品彩铃：
#1 流行歌曲
#    http://218.206.71.20:3000/0026ajx20081225tclmtk62251
#2 新歌
#    http://218.206.71.20:3000/0026ajx20081225tclmtk62252
#3 搞笑
#    http://218.206.71.20:3000/0026ajx20081225tclmtk62253
#4 经典
#    http://218.206.71.20:3000/0026ajx20081225tclmtk62254
#5 开通彩铃
#    http://218.206.71.20:3000/0025bjx20081225tclmtk6225
#6 我的彩铃库
#    http://218.206.71.20:3000/0025djx20081225tclmtk6225
#7 我的默认彩铃
#    http://218.206.71.20:3000/0025ejx20081225tclmtk6225
#client side
#8 订购彩铃
#    http://218.206.71.20:3001/0043cjx20081225tclmtk6225 + 歌曲ID号
#1 设为默认彩
#	http://218.206.71.20:3000/0043fjx20081225szymtk6225 + 歌曲ID号
#2 删除彩铃
#	http://218.206.71.20:3000/0043gjx20081225szymtk6225 + 歌曲ID
#3 取消默认彩铃
#	http://218.206.71.20:3000/0043hjx20081225szymtk6225 + 歌曲ID
#4 我的彩铃库+我的默认彩
#	http://218.206.71.20:3000/0025ijx20081225szymtk6225
#http://127.0.0.1:3001/0043cjx20081225tclmtk6225601510000000001175aa12345678901234567890110013911826145

class ToneManagerDebug():
    url = {};
    ip = "211.103.157.186";
    prefix1 = "";
    prefix2 = "";
    prefix3 = "";
    #prefix1 = "http://127.0.0.1:3001/0043";
    #prefix2 = "http://127.0.0.1:3001/0025";
    #prefix3 = "http://127.0.0.1:3001/0026";
    #phone="13901942311"; #上海
    #phone="13911826145"; #北京
    phone="13901942311"; #北京
    #id="601510000000001175";
    #id="601508000000002120";
    id="600902000000079395";
    fakemsg = "  X-Up-Calling-Line-ID: ";


    def __init__(self):
        self.prefix1 = "http://" + self.ip + ":3001/0043";
        self.prefix2 = "http://" + self.ip + ":3001/0025";
        self.prefix3 = "http://" + self.ip + ":3001/0026";
        self.url['OrderTone'] = self.prefix1 + "cjx20081225tclmtk6225" + self.id + self.fakemsg + "xx" + self.phone ;
        self.url['QueryMyTone'] = self.prefix2 + "djx20081225tclmtk6225" + self.fakemsg + "xx" + self.phone;
        self.url['QueryDefaultTone'] = self.prefix2 + "ejx20081225tclmtk6225" + self.fakemsg + "xx" + self.phone;
        self.url['OpenTone'] = self.prefix2 + "bjx20081225tclmtk6225" + self.fakemsg + "xx" + self.phone;
        self.url['ClassicalTone'] = self.prefix3 + "ajx20081225tclmtk6224" + self.fakemsg + "xx" + self.phone;
        self.url['FunnyTone'] = self.prefix3 + "ajx20081225tclmtk6223" + self.fakemsg + "xx" + self.phone;
        self.url['NewTone'] = self.prefix3 + "ajx20081225tclmtk6222" + self.fakemsg + "xx" + self.phone;
        self.url['PopTone'] = self.prefix3 + "ajx20081225tclmtk6221" + self.fakemsg + "xx" + self.phone;
        self.url['SetDefaultTone'] = self.prefix1 + "fjx20081225tclmtk6225" + self.id + self.fakemsg + "xx" + self.phone;
        self.url['DelTone'] = self.prefix1 + "gjx20081225tclmtk6225" + self.id + self.fakemsg + "xx" + self.phone;
        self.url['DelDefaultTone'] = self.prefix1 + "hjx20081225tclmtk6225" + self.id + self.fakemsg + "xx" + self.phone;
        self.url['MyToneAndDefaultTone'] = self.prefix2 + "ijx20081225tclmtk6225" + self.fakemsg + "xx" + self.phone;

    def popTone(self):
        url = urllib.urlopen(self.url['PopTone']);
        print self.url['PopTone'];
        print url.read(6);
        url.close();
    def newTone(self):
        url = urllib.urlopen(self.url['NewTone']);
        print self.url['NewTone'];
        print url.read(6);
        url.close();
    def funnyTone(self):
        url = urllib.urlopen(self.url['FunnyTone']);
        print self.url['FunnyTone'];
        print url.read(6);
        url.close();
    def classicalTone(self):
        url = urllib.urlopen(self.url['ClassicalTone']);
        print self.url['ClassicalTone'];
        print url.read(6);
        url.close();
    def orderToneList(self):
        print id;
        fd = open('sh_id_100_10.txt','r');
        for line in fd:
            self.url['OrderTone'] = self.prefix1 + "cjx20081225tclmtk6225" + line.strip() + self.fakemsg + "xx" + self.phone ;
            #print self.url['OrderTone'];
            url = urllib.urlopen(self.url['OrderTone']);
            res = url.read(6);
            if res == '0006C1':
                print line.strip() + ' OK.';
            else:
                print line.strip() + ' Failed.';
        fd.close();

    def orderTone(self, id = "619525000000004299"):
        self.url['OrderTone'] = self.prefix1 + "cjx20081225tclmtk6225" + id + self.fakemsg + "xx" + self.phone ;
        url = urllib.urlopen(self.url['OrderTone']);
        #print self.url['OrderTone'];
        print url.read(6);
        url.close();
    def queryMyTone(self):
        url = urllib.urlopen(self.url['QueryMyTone']);
        print self.url['QueryMyTone'];
        print url.read();
        url.close();
    def queryDefaultTone(self):
        url = urllib.urlopen(self.url['QueryDefaultTone']);
        print self.url['QueryDefaultTone'];
        print url.read();
        url.close();
    def openTone(self):
        url = urllib.urlopen(self.url['OpenTone']);
        print self.url['OpenTone'];
        print url.read();
        url.close();
    def setDefaultTone(self):
        url = urllib.urlopen(self.url['SetDefaultTone']);
        print self.url['SetDefaultTone'];
        print url.read();
        url.close();
    def delTone(self):
        url = urllib.urlopen(self.url['DelTone']);
        print self.url['DelTone'];
        print url.read();
        url.close();
    def delDefaultTone(self):
        url = urllib.urlopen(self.url['DelDefaultTone']);
        print self.url['DelDefaultTone'];
        print url.read();
        url.close();

if __name__ == '__main__':
    tm = ToneManagerDebug();
    #tm.orderTone();
    tm.orderToneList();
    #tm.queryDefaultTone();
    #tm.setDefaultTone();
    #tm.queryMyTone();
    #tm.delTone();
    #for v in tm.url.values():
    #    print v;

    

